/**
 * 静态代理
 */

export class Client {
  main() {
    const gamePlayer = new GamePlayer('张三')
    const proxyGamePlayer = new ProxyGamePlayer(gamePlayer)
    proxyGamePlayer.login()
    proxyGamePlayer.killBoss()
    for (let i = 0; i < 10; i++) {
      proxyGamePlayer.upgrade()
    }
    proxyGamePlayer.getCount()
  }
}

export interface IGamePlayer {
  login(): void
  killBoss(): void
  upgrade(): void
}

export class GamePlayer implements IGamePlayer {
  [x: string]: any
  _name: string = ''
  constructor(name: string) {
    this._name = name
  }
  login(): void {
    console.log(`${this._name}玩家登录游戏`);

  }
  killBoss(): void {
    console.log(`${this._name}玩家杀死了boss`);
  }
  upgrade(): void {
    console.log(`${this._name}玩家升级了`);
  }
}

export class ProxyGamePlayer implements IGamePlayer {
  private _gamePlayer: GamePlayer = null;
  private _count: number = 0
  constructor(gamePlayer: GamePlayer) {
    console.log('代理玩家登录');
    this._gamePlayer = gamePlayer
  }
  login(): void {
    this._gamePlayer.login()
  }
  killBoss(): void {
    this._gamePlayer.killBoss()
  }
  upgrade(): void {
    this._gamePlayer.upgrade()
    this._count = this._count + 1
  }
  getCount() {
    console.log(`代理玩家从${this._gamePlayer._name}那挣了${this._count}元钱`);
  }
}